package cn.stylefeng.guns.modular.api;

import cn.stylefeng.guns.base.consts.ConstantsContext;
import cn.stylefeng.guns.modular.business.common.GunsData;
import cn.stylefeng.guns.modular.business.entity.CategoryContent;
import cn.stylefeng.guns.modular.business.model.params.OrderParam;
import cn.stylefeng.guns.modular.business.model.params.OrderQueryParam;
import cn.stylefeng.guns.modular.business.model.result.IndexResult;
import cn.stylefeng.guns.modular.business.model.result.OrderResult;
import cn.stylefeng.guns.modular.business.service.CategoryContentService;
import cn.stylefeng.guns.modular.business.service.CategoryService;
import cn.stylefeng.guns.modular.business.service.IndexService;
import cn.stylefeng.guns.modular.business.service.OrderService;
import cn.stylefeng.guns.sys.core.util.StringUtils;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.MD5Util;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 订单表控制器
 *
 * @author jwj
 * @Date 2019-07-12 14:20:25
 */
@RestController
@RequestMapping("/gunsApi/index")
public class IndexApi extends BaseController {

    @Autowired
    private OrderService orderService;

    @Autowired
    CategoryService categoryService;

    @Autowired
    IndexService indexService;

    @Autowired
    CategoryContentService categoryContentService;


    @ApiOperation("首页")
    @PostMapping("")
    public ResponseData index() {
        IndexResult result = indexService.getIndexData();
        return ResponseData.success(result);
    }

    /**
     * 获取礼品卡所有分类
     * @return
     */
    @ApiOperation("礼品卡分类")
    @PostMapping("get-cards")
    public ResponseData getCardList() {
        String categoryId = (String) ConstantsContext.getConstntsMap().get("GUNS_INDEX_CARD_ID");
        return ResponseData.success(indexService.getAllCardList(categoryId));
    }

    /**
     * 获取积分卡所有分类
     * @return
     */
    @ApiOperation("礼品卡分类")
    @PostMapping("get-integrals")
    public ResponseData getIntegralsList() {
        String categoryId = (String) ConstantsContext.getConstntsMap().get("GUNS_INDEX_INTEGRAL_ID");
        return ResponseData.success(indexService.getAllCardList(categoryId));
    }


    /**
     * 获取所有分类和卡面值
     * @return
     */
    @ApiOperation("礼品卡分类和面值")
    @PostMapping("get-card-quota")
    public ResponseData getQuotaList() {
        String categoryId = (String) ConstantsContext.getConstntsMap().get("GUNS_INDEX_CARD_ID");
        return ResponseData.success(indexService.getAllCardListAndQuota(categoryId));
    }


    /**
     * 获取积分卡所有分类
     * @return
     */
    @ApiOperation("礼品卡分类")
    @GetMapping("clear")
    public ResponseData clear() {
        GunsData.clear();
        return ResponseData.success();
    }

    /**
     * 获取分类的获取方式
     * @return
     */
    @ApiOperation("获取分类的获取方式")
    @GetMapping("category-content")
    public ResponseData categoryContent(@RequestParam Long categoryId) {
        CategoryContent categoryContent = categoryContentService.getById(categoryId);
        if(categoryContent != null) {
            return ResponseData.success(categoryContent.getGetContent());
        }
        return ResponseData.error("无获取方式说明");
    }


}


